<?php
include_once( dirname(__FILE__) . DIRECTORY_SEPARATOR . "/main.inc");
session_start();
?>

<html>
<head>
	<title>Evernote: Sample Application Using OAuth</title>
	<script type="text/javascript" src="main.js"></script>
	<link rel="stylesheet" type="text/css" media="all" href="main.css" />
</head>
<body>
<div id="content">
	<h1>Sample Evernote application using OAuth</h1>
	
	<?php if (hasErrors()): ?>
		<ul class="appErrors">
		<?php foreach ($GLOBALS['app_errors'] as $err): ?>
			<li><?php echo $err ?></li>
		<?php endforeach; ?>
		</ul>
	<?php endif; ?>
	
	<?php if (!isAuthed()) doAuth(); ?>
	
	<?php if (!isAuthed()) { ?>
	<p>Please 
		<a href="#" onClick="openAuthDialog('<?php echo getAuthUrl();?>');">authorize</a> 
		<b>"<?php echo consumerName?>"</b> to access your Evernote account.
	</p>
	
	<?php } else { ?>
	<div id="listNotebooks">
		<h2>List of notebooks:</h2>
		<ul>
		<?php foreach (getNotebooks() as $notebook):?>
			<li><?php echo $notebook->name; ?></li>
		<?php endforeach; ?>
		</ul>
	</div>
	<?php } ?>
	
	<?php if (isAuthed()): ?>
		<a href="<?php echo $_SERVER['SCRIPT_NAME'] . "?action=resetSession" ?>">Reset</a>
	<?php endif; ?>
	
	<div id="authDialog" style="display: none;">
		<iframe id="authFrame" src="about:blank"></iframe>
	</div>
	
</div>
</body>
</html>
